package com.coco.statusbarheight;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONException;
import org.json.JSONObject;

public class StatusBarHeight extends CordovaPlugin {
    @Override
    public boolean execute(String action, String rawArgs, CallbackContext callbackContext) throws JSONException {

        if (action.equals("getValue")) {


            try {
                int resId = cordova.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android");

                callbackContext.success(new JSONObject()
                        .put("code", 0)
                        .put("dim", cordova.getContext().getResources().getDimension(resId))
                        .put("px", cordova.getContext().getResources().getDimensionPixelSize(resId)));

            } catch (Exception e) {

                callbackContext.error(new JSONObject()
                        .put("code", -1)
                        .put("dim", -1)
                        .put("px", -1));

                e.printStackTrace();
            }
            return true;
        }

        return false;
    }
}
